/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.wpi.first.wpilibj.templates;

/**
 * This class represents the hold of the robot,
 * which contains balls that have been picked up
 * by the harvester and are on their way to the
 * shooter. This class is thread-safe, as the
 * harvester and shooter may run on separate
 * threads.
 * @author 708
 */
public class Hold {

    private int numBalls = 0;

    /**
     * Loads the hold with 2 balls. Should be called
     * at the start of autonomous.
     */
    public synchronized void startAutonomous(){
        numBalls = 2;
    }

    /**
     * Removes one ball from the hold, representing
     * one shot fired.
     */
    public synchronized void shoot(){
        numBalls--;
    }

    /**
     * Adds one ball to the hold, representing
     * one ball collected.
     */
    public synchronized void harvest(){
        numBalls++;
    }

    /**
     * Check if the hold contains enough ammunition to
     * shoot.
     * @return
     */
    public synchronized boolean canShoot(){
        return numBalls > 0;
    }

    /**
     * Check if the hold has space for more balls.
     * @return
     */
    public synchronized boolean canHarvest(){
        return numBalls < 3;
    }

}
